Math.Abs 方法 (System) |
您所在的位置:网站首页 › 绝对值 最值 › Math.Abs 方法 (System) |
Source:Math.cs
Source:Math.cs
Source:Math.cs
返回单精度浮点数字的绝对值。 public: static float Abs(float value); public static float Abs (float value); static member Abs : single -> single Public Shared Function Abs (value As Single) As Single 参数 value Single大于或等于 Single.MinValue 但小于或等于 Single.MaxValue 的数字。 返回 Single单精度浮点数 x,使 0 ≤ x ≤ Single.MaxValue。 示例以下示例使用 Abs(Single) 方法获取多个 Single 值的绝对值。 float[] values= { Single.MaxValue, 16.354e-12F, 15.098123F, 0F, -19.069713F, -15.058e17F, Single.MinValue }; foreach (float value in values) Console.WriteLine($"Abs({value}) = {Math.Abs(value)}"); // The example displays the following output: // Abs(3.402823E+38) = 3.402823E+38 // Abs(1.6354E-11) = 1.6354E-11 // Abs(15.09812) = 15.09812 // Abs(0) = 0 // Abs(-19.06971) = 19.06971 // Abs(-1.5058E+18) = 1.5058E+18 // Abs(-3.402823E+38) = 3.402823E+38 open System let values = [ Single.MaxValue; 16.354e-12f; 15.098123f; 0f -19.069713f; -15.058e17f; Single.MinValue ] for value in values do // The 'abs' function may be used instead. printfn $"Abs({value}) = {Math.Abs value}" // The example displays the following output: // Abs(3.402823E+38) = 3.402823E+38 // Abs(1.6354E-11) = 1.6354E-11 // Abs(15.09812) = 15.09812 // Abs(0) = 0 // Abs(-19.06971) = 19.06971 // Abs(-1.5058E+18) = 1.5058E+18 // Abs(-3.402823E+38) = 3.402823E+38 Module Example Public Sub Main() Dim values() As Single = { Single.MaxValue, 16.354e-12, 15.098123, 0, _ -19.069713, -15.058e17, Single.MinValue } For Each value As Single In values Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value)) Next End Sub End Module ' The example displays the following output: ' Abs(3.402823E+38) = 3.402823E+38 ' Abs(1.6354E-11) = 1.6354E-11 ' Abs(15.09812) = 15.09812 ' Abs(0) = 0 ' Abs(-19.06971) = 19.06971 ' Abs(-1.5058E+18) = 1.5058E+18 ' Abs(-3.402823E+38) = 3.402823E+38 注解的 Single 绝对值是其不带符号的数值。 例如,1.2e-03 和 -1.2e03 的绝对值为 1.2e03。 如果 value 等于 NegativeInfinity 或 PositiveInfinity,则返回值为 PositiveInfinity。 如果 value 等于 NaN,则返回值为 NaN。 适用于 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |